package com.ruoyi.eqmonitor.controller;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.eqmonitor.service.LcyApiService;
import com.ruoyi.eqmonitor.utils.LechangeHttpSend;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@Api(tags = "乐橙云接口")
@RestController
@RequestMapping("/lcyApi")
public class LcyApiController {

    @Autowired
    private LcyApiService lcyApiService;

    @ApiOperation("查询设备本地录像片段")
    @GetMapping("/queryLocalRecords")
    public AjaxResult queryLocalRecords(@RequestParam("deviceId") String deviceId,
                                        @RequestParam("beginTime") String beginTime,
                                        @RequestParam("endTime") String endTime){
        String accessToken = lcyApiService.getAccessToken();
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("token",accessToken);
        paramMap.put("deviceId",deviceId);
        paramMap.put("beginTime",beginTime);
        paramMap.put("endTime",endTime);
        return AjaxResult.success(LechangeHttpSend.queryLocalRecords(paramMap));
    }

    @ApiOperation("云台移动控制")
    @GetMapping("/controlMovePTZ")
    public AjaxResult controlMovePTZ(@RequestParam("deviceId") String deviceId,
                                     @RequestParam("operation") String operation,
                                     @RequestParam("duration") Long duration){
        String accessToken = lcyApiService.getAccessToken();
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("token",accessToken);
        paramMap.put("deviceId",deviceId);
        //0-上，1-下，2-左，3-右，4-左上，5-左下，6-右上，7-右下，8-放大，9-缩小，10-停止
        paramMap.put("operation",operation);
        paramMap.put("duration",duration);
        return AjaxResult.success(LechangeHttpSend.controlMovePTZ(paramMap));
    }

    @ApiOperation("获取KitToken")
    @GetMapping("/getKitToken")
    public AjaxResult getKitToken(@RequestParam("deviceId") String deviceId){
        String accessToken = lcyApiService.getAccessToken();
        Map<String, Object> paramMap = new HashMap<>();
        paramMap.put("token",accessToken);
        paramMap.put("deviceId",deviceId);
        return AjaxResult.success(LechangeHttpSend.getKitToken(paramMap));
    }

}
